<!DOCTYPE html>
<html lang="en">
<head>
  <title></title>
  <script type="text/javascript" src="../internal.js"></script>
  <style>
    #select-list input{
      display: inline-block;
      width: 100px;
    }
  </style>
</head>
<body>
<div>
  <div>
    <label>合同属性</label>
    <select id="selectCode">
      <option value="">无</option>
    </select>
  </div>
  <div>
    <button onclick="appendOption()">添加选项</button>
  <ul id="select-list">
    <li>
      选项:<input id="select-list-value-0"/>
    </li>
  </ul>
 </div>
 <div> <button onclick="submit()">确定</button></div>
</div>
</body>
<script>
  function submit(){
    var id = 'select' + Math.random().toString().slice(-10);
    var str = '<select class="ue-select" style="width: 180px" id="' + id + '">';
    var len = document.getElementById('select-list').children.length;
    var list = [];
    for (var i=0; i < len; i++) {
      var value = document.getElementById('select-list-value-' + i).value;
      str += '<option value="'+ value +'">'+ value +'</option>';
      list.push({
        value: value
      });
    }
    str += '</select>';
    var code = document.getElementById('selectCode').value;
    editor.execCommand('insertHtml',str, true);
    editor.elList.push({
        elId: id,
        elType: 'select',
        elContent:JSON.stringify(list),
        elField: code
    });
    dialog.popup.hide();
  }
  function appendOption() {
    var ul = document.getElementById('select-list');
    var len = ul.children.length;
    var li = document.createElement("li");
    li.append('value:');
    var input1 = document.createElement("input");
    input1.id = 'select-list-value-' + len ;
    li.appendChild(input1);
    // li.append('label:');
    // var input2 = document.createElement("input");
    // input2.id = 'select-list-label-' + len;
    // li.appendChild(input2);
    var delBtn = document.createElement('button');
    delBtn.innerText = '删除';
    delBtn.addEventListener('click',function () {
      this.parentNode.parentNode.removeChild(this.parentNode);
    });
    li.appendChild(delBtn);
    ul.appendChild(li);
  }
</script>
</html>
